package com.example.fakertest.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.fakertest.entity.User;
import com.example.fakertest.utils.FakerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Fakername {

    @Autowired
    User user;

    @Autowired
    FakerUtils fakerUtils;

    @GetMapping("/")
    public User test(){
        user.setName(fakerUtils.faker.name().fullName());
        user.setAge(29);
        user.setAddress("南通如皋");
        System.out.println(user);
        //Java对象转换成JSON字符串
//        String stuString = JSONObject.toJSONString(user);
        return user;
    }
}
